//	获取url传值
function getQueryString(name) {
	var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
	if (result == null || result.length < 1) {return "";}
		return result[1];
}
id = getQueryString("id");

$.validator.setDefaults({
    submitHandler: function() {
      	var params = $(".form-div").serialize()+'&goodsId='+goodsId+'&goodsInfoId='+id; 
      	$.ajax( {  
                type : "POST",  
                url : serverIP+"/user/goodsInfo/save",  
                data : params,  
                xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
                success : function(data) {
                	if(data.code==0){
                		alert("修改成功");
                	}else{
                		alert(data.msg);
                	}
                }  
        }); 
    }
});

$(document).ready(function() {
	$('.form-div').validate({
		rules: {
		 	name: "required",
		 	goodsCode: "required",
		 	supplier: "required"
		},
		messages: {
	      	name: "请输入商品名称",
	      	goodsCode: "请输入编码",
	      	supplier: "请输入供应商"
		}	
	})
})
$(function(){
	if($(".admin").height()<600){
		$('.nav-btn').height('50px').find('img').hide();
	}else{
		$('.nav-btn').height('150px').find('img').show();
	}
//	获取物料详情信息
	$.ajax({
		type:"get",
		url:serverIP+"/user/goodsInfo/view?goodsInfoId="+id,
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
		success:function (data) {
			goodsId=data.data.goodsId;
			$('input[name="name"]').val(data.data.goodsName);
			$('input[name="goodsCode"]').val(data.data.goodsCode);
			$('input[name="goodsBarCode"]').val(data.data.goodsBarCode);
			if(data.data.property==01){
				$('#property1').prop("checked",true);
			}else if(data.data.property==02){
				$('#property2').prop("checked",true);
			}
			$('input[name="supplier"]').val(data.data.supplier);
			$('input[name="remark"]').val(data.data.remark);
		}
	})	
})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
	if($(".admin").height()<600){
		$('.nav-btn').height('50px').find('img').hide();
	}else{
		$('.nav-btn').height('150px').find('img').show();
	}
}
$(".icon-ok").click(function() {
	$(".submit").click();
})
$(".back").click(function() {
	history.back();
});